package net.xdclass.vo;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.math.BigDecimal;
import java.util.List;

public class CartVO {
    @JsonProperty("cart_items")
    private List<CartItemVO> cartItems;

    @JsonProperty("total_num")
    private Integer totalNum;

    @JsonProperty("total_price")
    private BigDecimal totalPrice;

    @JsonProperty("real_pay_price")
    private BigDecimal realPayPrice;

    public List<CartItemVO> getCartItems() {
        return cartItems;
    }

    public void setCartItems(List<CartItemVO> cartItems) {
        this.cartItems = cartItems;
    }

    public Integer getTotalNum() {
        if (this.cartItems != null) {
            int total = cartItems.stream().mapToInt(CartItemVO::getBuyNum).sum();
            return total;
        }
        return 0;
    }

    public void setTotalNum(Integer totalNum) {
        this.totalNum = totalNum;
    }

    public BigDecimal getTotalPrice() {
        BigDecimal amount = new BigDecimal("0");
        if (this.cartItems != null) {
            amount = this.cartItems.stream()
                    .map(CartItemVO::getTotalAmount)
                    .reduce(amount, (acc, item) -> acc.add(item));
            return amount;
        }

        return amount;
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    public BigDecimal getRealPayPrice() {
        return realPayPrice;
    }

    public void setRealPayPrice(BigDecimal realPayPrice) {
        this.realPayPrice = realPayPrice;
    }
}
